package com.operation;

import java.util.Date;

import org.json.JSONObject;

import com.service.AreainfoService;

public class FreeLink {
	/**
	 * 时长免费上网验证
	 * @param userid
	 * @param url
	 * @param gateIp
	 * @return
	 * @throws Exception 
	 */
	
	public static int timingFristFreeVerify(int userid,String url,String gateIp) throws Exception{
		
		HttpSendUrl send = new HttpSendUrl();
		
		url = "http://"+gateIp+url+"?userid="+userid;
		int ru = 0;
		int code=-1;
		int isExist = -1;
		int netTime = -1;
		try {
			String sendRequest = send.getSendRequest(url,"", "get", 5000);
			JSONObject js = new JSONObject(sendRequest);
			
			if(js.has("code"))
				code=Integer.parseInt(js.get("code").toString());
			if(js.has("isExist"))
				isExist = Integer.parseInt(js.get("isExist").toString());
			if(js.has("netTime"))
				netTime = Integer.parseInt(js.get("netTime").toString());
			
			if(code==1&&isExist==0){
				ru=1;
			}
			if(code==1&&isExist==1&&netTime==1){
				ru=2;
			}
		} catch (Exception e){
			ru=-1;
			e.printStackTrace();
		}
		System.out.println("时长免费上网验证--结果ru---:"+ru);
		return ru;
	}
}
